<?php


namespace App\Http\Requests\Product\Index;


use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class StoreRequest extends FormRequest
{
    /**
     * @return array
     * @author luffyzhao@vip.126.com
     */
    public function rules()
    {
        return [
            'customer_id' => ['required', Rule::unique('products', 'customer_id')->where('code', $this->input('code'))],
            'code' => ['required', 'alpha_dash'],
            'title' => ['required', 'max:255'],
            'gross_weight' => ['numeric', 'required'],
            'picture' => ['nullable', 'max:255'],
            'brand' => ['required', 'max:100'],
            'customs.code' => ['required', 'size:10'],
            'customs.qy1' => ['required', 'numeric'],
            'customs.qy2' => ['nullable', 'numeric', 'nullable'],
            'customs.name' => ['required', 'max:255'],
            'customs.unit' => ['required', 'size:3', Rule::exists('units', 'code')],
            'customs.unit1' => ['required', 'size:3', Rule::exists('units', 'code')],
            'customs.unit2' => ['nullable', 'size:3', Rule::exists('units', 'code')],
            'customs.country' => ['required', 'size:3', Rule::exists('country', 'code')],
            'customs.net_weight' => ['required', 'numeric'],
            'customs.element' => ['required', 'max:255'],
        ];
    }
}
